import 'package:flutter/material.dart';
import 'package:file_picker/file_picker.dart';
import 'dart:io';

import 'package:sharing/utils/whole_apis.dart';
import 'package:sharing/net/net_util.dart';
import 'package:dio/dio.dart';
import 'package:sharing/net/ris_read_apis.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:dio/dio.dart';
import 'package:sharing/model/book_list.dart';
import 'package:sharing/ui/experience/experience.dart';
import 'package:sharing/ui/widget/user_login.dart';
const String fontFamily = 'iconFont';

class GenerateOriginWork extends StatefulWidget {
  @override
  _GenerateOriginWorkState createState() => _GenerateOriginWorkState();
}

class _GenerateOriginWorkState extends State<GenerateOriginWork> {
  String _coverUrl = "";
  String _title = "";
  String _instruction = "";
  String _selectedFile = "";
  int _authority = 0;
  bool _contentFocus = true;
  int _bookInfoType = 1;
  String _bookInfoReward = "5";
  String _bookInfoLink = "";
  Map<String,int> mapBookTypes = {'科技':1,
  '札记':2,
  '历史':3,
  '金融':4,
  '其他':5,};

  // 文章的封面发生变化
  ValueChanged<String> _onCoverPathChange(String value) {
    print(" _onCoverPathChange(String $value)");
    _coverUrl = value;
  }

  // 文章的标题发生变化
  ValueChanged<String> _onTitleChange(String value) {
    print(" ValueChanged<String> _onTitleChange(String ${value})");
    _title = value;
  }

  // 文章的介绍发生变化
  ValueChanged<String> _onInstructionChange(String value) {
    _instruction = value;
  }

  // 上传书籍的文件选择
  ValueChanged<String> _onFileSelected(String value) {
    _selectedFile = value;
  }

  // 文章的类型发生变化
  ValueChanged<String> _onBookInfoTypeChanged(String value) {
    _bookInfoType = mapBookTypes[_bookInfoType]==null?1: mapBookTypes[_bookInfoType];
  }

  // 文章阅读的奖励分数选择
  ValueChanged<String> _onBookInfoRewardChanged(String value) {
    _bookInfoReward = value;
  }

  // 文章的连接发生变化
  ValueChanged<String> _onLinkChanged(String value) {
    _bookInfoLink = value;
  }

  // 文章的权限发生变化
  ValueChanged<int> _onAuthorityChange(int _selected) {
    _authority = _selected;
    print("_authority is ${_authority}");
  }

  void _commitBookInfo() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    String authorization = await prefs.getString("authorization");
    var formData = new FormData.from({
      "name": _title, //文章的标题
      "instruction": _instruction, // 介绍
      "type": _bookInfoType, // 书籍的类型
      "reward": _bookInfoReward, // 奖励的分数
      "link": _bookInfoLink, // 书籍的连接
      "type_id":_bookInfoType,
      "cover": new UploadFileInfo(new File(_coverUrl), _coverUrl),
      "pdf": new UploadFileInfo(new File(_selectedFile), _selectedFile),
    });

    var options = Options(headers: {"authorization": authorization});
    new Dio()
        .post(WholeApis.hostName + RisReadApis.commitBookInfo,
            data: formData, options: options)
        .then((Response response) {
      print("response ${response.data}");

      var code = response.data["code"];

      if (code == 409){
        // 移除 au
        // 用户登录过期, 需要用户重新登录
        //
         _removeAu();
        Navigator.of(context).pushReplacement(MaterialPageRoute(builder: (context){
          return Login();
        }));
      } else if (code == 200){
        // 用户发布书籍成功
        Navigator.of(context).pop();
      }

    });
  }

  void _removeAu()async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    prefs.remove("authorization");
  }
  @override
  Widget build(BuildContext context) {
    return Material(
      child: Scaffold(
        appBar: _buildAppBar(context),
        body: Container(
          width: double.infinity,
          height: double.infinity,
          child: Stack(
            fit: StackFit.expand,
            children: <Widget>[
              SingleChildScrollView(
                child: Column(
                  children: <Widget>[
                    // 封面
                    _OriginCover(
                      url: _coverUrl,
                      onChanged: _onCoverPathChange,
                    ),

                    // 书籍的名称
                    _OriginTitle(
                      onTitleChange: _onTitleChange,
                      title: _title,
                    ),

                    SizedBox(
                      height: 8.0,
                      child: Container(color: Colors.black12),
                    ),
                    // 书籍的介绍说明
                    _OriginInstruction(
                      onInstructionChange: _onInstructionChange,
                    ),

                    // 选择书籍文件上传
                    _OriginFileSelect(
                      onFileSelected: _onFileSelected,
                    ),

                    // 文章书籍的类型
                    _OriginBookInfoTypeSelected(
                      bookInfoTypeChanged: _onBookInfoTypeChanged,
                    ),

                    // 奖励的分数
                    _OriginBookInfoReward(),
                    _OriginAuthority(
                      authorityChanged: _onAuthorityChange,
                    ),

                    // 文章的来源
                    Container(
                      // color: Colors.orange,
                      padding: const EdgeInsets.symmetric(
                          horizontal: 4.0, vertical: 4.0),
                      child: TextField(
                        maxLength: 300,
                        maxLines: 1,
                        onChanged: _onLinkChanged,
                        style: TextStyle(
                          fontSize: 14.0,
                          color: Colors.black,
                          fontWeight: FontWeight.normal,
                        ),
                        decoration: InputDecoration(
                          hintText: "文章来源 ",
                          hintStyle: TextStyle(
                            fontWeight: FontWeight.bold,
                            fontSize: 14.0,
                            color: Colors.black26,
                          ),
                        ),
                      ),
                    ),
                  ],
                ),
              ),
//              Positioned(
//                bottom: 1.0,
//                left: 0,
//                right: 0.0,
//                height: 44.0,
//                child: Container(
//                  color: Colors.grey[200],
//                  child: Row(
//                    mainAxisAlignment: MainAxisAlignment.start,
//                    crossAxisAlignment: CrossAxisAlignment.center,
//                    children: <Widget>[
//                      Container(
//                        padding: const EdgeInsets.symmetric(horizontal: 8.0),
//                        child: GestureDetector(
//                          onTap: () {
//                            print("hello world");
//                          },
//                          child: Icon(
//                            IconData(0xe617, fontFamily: fontFamily),
//                            color: Color(0xff182748),
//                            size: 32,
//                          ),
//                        ),
//                      ),
//                      // 分割线
//                      Container(
//                        padding: const EdgeInsets.symmetric(horizontal: 0.0),
//                        child: Icon(
//                          IconData(
//                            0xe680,
//                            fontFamily: fontFamily,
//                          ),
//                          color: Color(0xff182748),
//                          size: 14,
//                        ),
//                      ),
//                      // 标题
//                      Container(
//                        padding: const EdgeInsets.symmetric(horizontal: 8.0),
//                        child: Icon(
//                          IconData(
//                            0xec84,
//                            fontFamily: fontFamily,
//                          ),
//                          color: Color(0xff182748),
//                          size: 24,
//                        ),
//                      ),
//                      // 加粗
//                      Container(
//                        padding: const EdgeInsets.symmetric(horizontal: 8.0),
//                        child: Icon(
//                          IconData(
//                            0xe625,
//                            fontFamily: fontFamily,
//                          ),
//                          color: Color(0xff182748),
//                          size: 32,
//                        ),
//                      ),
//                      //&#xe665; 撤回
//                      Container(
//                        padding: const EdgeInsets.symmetric(horizontal: 8.0),
//                        child: Icon(
//                          IconData(
//                            0xe62a,
//                            fontFamily: fontFamily,
//                          ),
//                          color: Color(0xff182748),
//                          size: 32,
//                        ),
//                      ),
//                    ],
//                  ),
//                ),
//              ),
            ],
          ),
        ),
      ),
    );
  }

  AppBar _buildAppBar(BuildContext context) {
    return AppBar(
      backgroundColor: Color(0x142740),
      title: Text("投稿新书"),
      actions: <Widget>[
        IconButton(
          icon: Text("完成"),
          onPressed: () {
            _commitBookInfo();
          },
        ),
      ],
    );
  }
}

class _OriginCover extends StatefulWidget {
  _OriginCover({Key key, @required this.url, @required this.onChanged})
      : super(key: key);
  String url = "";

  // String url ="https://flutter.io/assets/404/dash_nest-c64796b59b65042a2b40fae5764c13b7477a592db79eaf04c86298dcb75b78ea.png";
  @override
  __OriginCoverState createState() => __OriginCoverState();

  final ValueChanged<String> onChanged;
}

class __OriginCoverState extends State<_OriginCover> {
  __OriginCoverState({this.onChanged});

  final ValueChanged<String> onChanged;

  @override
  Widget build(BuildContext context) {
    return _buildBody(context);
  }

  Widget _buildBody(BuildContext context) {
    return Container(
      height: 160.0,
      width: double.infinity,
      margin: const EdgeInsets.all(0.0),
      padding: const EdgeInsets.all(0.0),
      decoration: BoxDecoration(
        //  color: Colors.orange,
        borderRadius: BorderRadius.only(
          topLeft: Radius.circular(4.0),
          topRight: Radius.circular(4.0),
          bottomLeft: Radius.circular(4.0),
          bottomRight: Radius.circular(4.0),
        ),
      ),
      child: widget.url == "" ? _buildChoose(context) : _buildImg(context),
    );
  }

  Widget _buildImg(BuildContext context) {
    return InkWell(
      onTap: () async {
        showModalBottomSheet(
            context: context, builder: _buildDelChoseImgBottomSheet);
      },
      child: widget.url.startsWith("http")
          ? Image.network(
              widget.url,
              fit: BoxFit.cover,
            )
          : Image.file(
              new File(widget.url),
              fit: BoxFit.cover,
            ),
    );
  }

  Widget _buildChoose(BuildContext context) {
    return Container(
      decoration: BoxDecoration(
        color: Colors.grey[100],
      ),
      child: InkWell(
        onTap: () async {
          print("select image");
          String _path = await FilePicker.getFilePath(
            type: FileType.IMAGE,
          ); // will filter and display only files with SVG extension.
          if (_path == null) {
            return;
          }
          print("_path is ${_path}");
          widget.onChanged(_path);
          setState(() {
            widget.url = _path;
          });
        },
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: <Widget>[
            Container(
              margin: const EdgeInsets.symmetric(vertical: 4.0),
              //  color: Colors.orange,
              height: 72,
              width: 72,
              child: Image.asset(
                  "asset/origin_work/img/zhuanlan_cover_pick_img.png"),
            ),
            Container(
              margin: const EdgeInsets.symmetric(vertical: 4.0),
              child: Text(
                "添加书籍封面",
                style: TextStyle(color: Colors.black26, fontSize: 14.0),
              ),
            ),
            Container(
              margin: const EdgeInsets.symmetric(vertical: 4.0),
              child: Text(
                "(支持8MB以内)",
                style: TextStyle(color: Colors.black26, fontSize: 12.0),
              ),
            ),
          ],
        ),
      ),
    );
  }

  // 构建底部菜单选项
  Widget _buildDelChoseImgBottomSheet(BuildContext context) {
    return Container(
      height: 200.0,
      decoration: BoxDecoration(
        color: Colors.grey[600],
      ),
      child: Column(
        children: <Widget>[
          Container(
            width: double.infinity,
            child: Column(
              children: <Widget>[
                Container(
                  padding: const EdgeInsets.symmetric(vertical: 8.0),
                  margin: const EdgeInsets.symmetric(
                    horizontal: 8.0,
                    vertical: 8.0,
                  ),
                  decoration: BoxDecoration(
                      color: Colors.white,
                      borderRadius: BorderRadius.circular(16.0)),
                  child: Column(
                    children: <Widget>[
                      Container(
                        padding: const EdgeInsets.symmetric(vertical: 4.0),
                        child: Text(
                          "删除/替换 图片为不可逆操作,请您确定 ? ",
                          textAlign: TextAlign.center,
                          style: TextStyle(
                            fontSize: 12.0,
                            color: Colors.grey[500],
                          ),
                        ),
                      ),
                      Container(
                        padding: const EdgeInsets.symmetric(horizontal: 8),
                        child: Divider(
                          height: .8,
                          color: Colors.grey[600],
                        ),
                      ),
                      Container(
                        margin: const EdgeInsets.symmetric(
                            vertical: 8, horizontal: 8.0),

                        decoration: BoxDecoration(
                          color: Colors.transparent,
                          borderRadius: BorderRadius.circular(8.0),
                        ),
                        // color: Colors.white,
                        child: InkWell(
                          onTap: () {
                            _deleteImg(context);
                          },
                          child: Text(
                            "删 除",
                            style: TextStyle(
                              fontSize: 18,
                              color: Colors.red,
                              fontWeight: FontWeight.normal,
                            ),
                          ),
                        ),
                      ),
                      Container(
                        padding: const EdgeInsets.symmetric(horizontal: 8),
                        child: Divider(
                          height: .8,
                          color: Colors.grey[600],
                        ),
                      ),
                      Container(
                        width: double.infinity,
                        margin: const EdgeInsets.symmetric(
                            horizontal: 8.0, vertical: 0.0),
                        padding: const EdgeInsets.symmetric(vertical: 4.0),
                        decoration: BoxDecoration(
                          borderRadius: BorderRadius.circular(16.0),
                          color: Colors.white,
                        ),
                        child: InkWell(
                          child: Text(
                            "重新选择图片",
                            textAlign: TextAlign.center,
                            style: TextStyle(
                              fontSize: 18.0,
                              color: Color(0xff182748),
                            ),
                          ),
                          onTap: () {
                            _selectImg(context);
                          },
                        ),
                      ),
                    ],
                  ),
                ),
              ],
            ),
          ),
          Container(
            alignment: Alignment.center,
            width: double.infinity,
            padding: const EdgeInsets.symmetric(vertical: 8.0),
            margin: const EdgeInsets.symmetric(horizontal: 8.0, vertical: 8.0),
            decoration: BoxDecoration(
              color: Colors.white,
              borderRadius: BorderRadius.circular(16),
            ),
            child: InkWell(
              onTap: () {
                Navigator.of(context).pop();
              },
              child: Text(
                "取消",
                textAlign: TextAlign.center,
                style: TextStyle(
                  fontSize: 18.0,
                  color: Color(0xff182748),
                ),
              ),
            ),
          ),
        ],
      ),
    );
  }

  // 将封面的图片删除
  // 删除 cover url
  // 重新绘制封面
  // 弹出 cover url
  void _deleteImg(BuildContext context) async {
    await widget.onChanged("");
    setState(() {
      widget.url = "";
    });

    Navigator.of(context).pop();
  }

  // 重新选择图片
  // 将图片的地址设置为cover url
  // 重新绘制 url
  // 弹出 底部的菜单
  void _selectImg(BuildContext context) async {
    String _path = await FilePicker.getFilePath(
      type: FileType.IMAGE,
    );

    if (_path == null) {
      print("");
      return;
    }
    // 回调 重新设置 cover image url
    widget.onChanged(_path);
    setState(() {
      widget.url = _path;
    });

    // 弹出 底部的菜单
    Navigator.of(context).pop();
  }
}

// 文章的标题
class _OriginTitle extends StatefulWidget {
  _OriginTitle({@required this.onTitleChange, @required this.title})
      : assert(onTitleChange != null && title != null);

  String title = "";
  final ValueChanged<String> onTitleChange;

  @override
  __OriginTitleState createState() => __OriginTitleState();
}

class __OriginTitleState extends State<_OriginTitle> {
  @override
  Widget build(BuildContext context) {
    return Container(
      // color: Colors.orange,
      padding: const EdgeInsets.symmetric(horizontal: 4.0, vertical: 4.0),
      child: TextField(
        maxLength: 40,
        onChanged: _titleChange,
        style: TextStyle(
          fontSize: 20.0,
          color: Colors.black,
          fontWeight: FontWeight.bold,
        ),
        decoration: InputDecoration(
          hintText: "标题 (建议30字以内)",
          hintStyle: TextStyle(
            fontWeight: FontWeight.bold,
            fontSize: 14.0,
            color: Colors.black26,
          ),
        ),
      ),
    );
  }

  void _titleChange(String value) async {
    widget.title = value;
    // 回调函数, page 标题发生变化
    await widget.onTitleChange(value);
  }
}

// 文本的初始介绍说明
class _OriginInstruction extends StatefulWidget {
  final ValueChanged<String> onInstructionChange;

  _OriginInstruction({@required this.onInstructionChange});

  @override
  __OriginInstructionState createState() => __OriginInstructionState();
}

class __OriginInstructionState extends State<_OriginInstruction> {
  @override
  Widget build(BuildContext context) {
    return Container(
      // color: Colors.orange,
      padding: const EdgeInsets.symmetric(horizontal: 4.0, vertical: 4.0),
      child: TextField(
        maxLength: 40,
        maxLines: 2,
        onChanged: _valueChange,
        style: TextStyle(
          fontSize: 20.0,
          color: Colors.black,
          fontWeight: FontWeight.bold,
        ),
        decoration: InputDecoration(
          hintText: "介绍 (建议30字以内)",
          hintStyle: TextStyle(
            fontWeight: FontWeight.bold,
            fontSize: 14.0,
            color: Colors.black26,
          ),
        ),
      ),
    );
  }

  void _valueChange(String value) async {
    await widget.onInstructionChange(value);
  }
}

// 用户选择文件
class _OriginFileSelect extends StatefulWidget {
  _OriginFileSelect({@required this.onFileSelected});

  final ValueChanged<String> onFileSelected;

  @override
  __OriginFileSelectState createState() => __OriginFileSelectState();
}

class __OriginFileSelectState extends State<_OriginFileSelect> {
  String fileName = "请选择文件";

  @override
  Widget build(BuildContext context) {
    return Container(
      height: 54,
      width: double.infinity,
      child: InkWell(
        // 点击选择文件
        onTap: _selectedFileTap,
        // 显示文件名
        child: Container(
          margin: const EdgeInsets.only(left: 8.0),
          child: Text(fileName),
        ),
      ),
    );
  }

  // 选择文件响应
  void _selectedFileTap() async {
    // 选择PDF 文件
    String selectedPath = await FilePicker.getFilePath(
        type: FileType.CUSTOM, fileExtension: "PDF");
    print("selectedPath $selectedPath");
    if (selectedPath == null) {
      return;
    }

    //
    widget.onFileSelected(selectedPath);

    // 提取文件名
    List<String> splits = selectedPath.split("/");
    String fn = splits[splits.length - 1].split(".pdf")[0];

    setState(() {
      // 设置要显示的文件名
      fileName = fn;
    });
  }
}

// 书籍的类型
class _OriginBookInfoTypeSelected extends StatefulWidget {
  _OriginBookInfoTypeSelected({Key key, @required this.bookInfoTypeChanged});

  final ValueChanged<String> bookInfoTypeChanged;

  @override
  __BookInfoTypeSelectedState createState() => __BookInfoTypeSelectedState();
}



class __BookInfoTypeSelectedState extends State<_OriginBookInfoTypeSelected> {
  final List<String> _allActivities = <String>[
    '科技',
    '札记',
    '历史',
    '金融',
    '其他',
  ];
  String _activity = "札记";

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: const EdgeInsets.symmetric(horizontal: 8.0),
      width: double.infinity,
      child: InputDecorator(
        decoration: const InputDecoration(
          labelText: '请选择书籍的类型',
          hintText: 'Choose an activity',
          contentPadding: EdgeInsets.zero,
        ),
        isEmpty: _activity == null,
        child: DropdownButton<String>(
          value: _activity,
          onChanged: (String newValue) {
            setState(() {
              _activity = newValue;
              widget.bookInfoTypeChanged(newValue);
            });
          },
          items: _allActivities.map<DropdownMenuItem<String>>((String value) {
            return DropdownMenuItem<String>(
              value: value,
              child: Text(value),
            );
          }).toList(),
        ),
      ),
    );
  }
}

class _OriginBookListNameSelected extends StatefulWidget {
  final ValueChanged<String> bookListSelected;
  _OriginBookListNameSelected({@required this.bookListSelected});
  @override
  __OriginBookListNameSelectedState createState() => __OriginBookListNameSelectedState();
}

class __OriginBookListNameSelectedState extends State<_OriginBookListNameSelected> {
  List<BookList> _bookLists = [];
  List<String > _allActivities = [];
  String _activity = null ;
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _fetchBookList();
  }
  
  void _fetchBookList()async{
    SharedPreferences prefs = await SharedPreferences.getInstance();
    String authorization = await prefs.getString("authorization");

    NetUtil.originGet(WholeApis.hostName+RisReadApis.ownBookList, Options(headers: {}), (Response response){
      print("data > ${response.data}");

      int code = response.data["code"];

      if (code == 200){
        _bookLists = BookList.fromJson(response.data["message"]);

        _bookLists.forEach((bl){
          _allActivities.add(bl.name);
        });
        setState(() {
          print("更新数据....");
        });
      }
    });
  }
  @override
  Widget build(BuildContext context) {
    return   Container(
      margin: const EdgeInsets.symmetric(horizontal: 8.0),
      width: double.infinity,
      child: InputDecorator(
        decoration: const InputDecoration(
          labelText: '请选择书籍的类型',
          hintText: 'Choose an activity',
          contentPadding: EdgeInsets.zero,
        ),
        isEmpty: _activity == null,
        child: DropdownButton<String>(
          value: _activity,
          onChanged: (String newValue) {
            setState(() {
              _activity = newValue;
              widget.bookListSelected(newValue);
            });
          },
          items: _allActivities.map<DropdownMenuItem<String>>((String value) {
            return DropdownMenuItem<String>(
              value: value,
              child: Text(value),
            );
          }).toList(),
        ),
      ),
    );;
  }
}

class _OriginBookInfoReward extends StatefulWidget {
  final ValueChanged<String> onValueChanged;

  _OriginBookInfoReward({Key key, this.onValueChanged}) : super(key: key);

  @override
  __OriginBookInfoRewardState createState() => __OriginBookInfoRewardState();
}

class __OriginBookInfoRewardState extends State<_OriginBookInfoReward> {
  final List<String> _allActivities = <String>[
    '1',
    '2',
    '3',
    '4',
    '5',
    '6',
    '7',
    '8',
    '9',
    '10',
  ];
  String _activity = "5";

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: const EdgeInsets.symmetric(horizontal: 8.0),
      width: double.infinity,
      child: InputDecorator(
        decoration: const InputDecoration(
          labelText: '请选择奖励的分数',
          hintText: 'Choose an activity',
          contentPadding: EdgeInsets.zero,
        ),
        isEmpty: _activity == null,
        child: DropdownButton<String>(
          value: _activity,
          onChanged: (String newValue) {
            setState(() {
              _activity = newValue;
              widget.onValueChanged(newValue);
            });
          },
          items: _allActivities.map<DropdownMenuItem<String>>((String value) {
            return DropdownMenuItem<String>(
              value: value,
              child: Text(value),
            );
          }).toList(),
        ),
      ),
    );
  }
}

// 文章心得的权限选择
class _OriginAuthority extends StatefulWidget {
  _OriginAuthority({Key key, @required this.authorityChanged})
      : assert(authorityChanged != null),
        super(key: key);

  @override
  __OriginAuthorityState createState() => __OriginAuthorityState();

  // 文章的心得发生变化的联动
  final ValueChanged<int> authorityChanged;
}

class __OriginAuthorityState extends State<_OriginAuthority> {
  // 权限 说明
  Map<int, String> _authorities_detail = {
    0: '他人可对专栏内容进行转载|复制,但是转载需要标注文章的作者、出处、来源',
    1: '非公开发布的心得,仅仅作者可见'
  };

  // 权限
  List<String> _authorities = ['允许规范转载', '个人心得'];
  int selected = 0;

  ValueChanged<int> onSelectedChanged(int _index) {
    widget.authorityChanged(_index);
    setState(() {
      selected = _index;
    });
  }

  // 迭代器生成list
  Iterable<Widget> get _inputSelects sync* {
    for (int i = 0; i < _authorities.length; i++) {
      yield InputSelect(
        index: i,
        choice: _authorities[i],
        parent: this,
      );
    }
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: const EdgeInsets.symmetric(horizontal: 8.0, vertical: 4.0),
      decoration: BoxDecoration(
        border: Border(
          top: BorderSide(color: Colors.grey, width: 0.1),
        ),
      ),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.start,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          Container(
            //color: Colors.orange,
            alignment: Alignment.centerLeft,
            child: Text(
              "请选择心得权限",
              style: TextStyle(
                color: Color(0xff182748),
                fontSize: 16.0,
              ),
            ),
          ),
          Container(
            child: Wrap(
              // 使用迭代器的方法生成list
              children: _inputSelects.toList(),
            ),
          ),
          Container(
            alignment: Alignment.centerLeft,
            padding: const EdgeInsets.symmetric(vertical: 4.0),
            child: Text(
              "©版权摘要说明: ${_authorities_detail[selected] == null ? "" : _authorities_detail[selected]}",
              style: TextStyle(
                color: Colors.grey[500],
                fontSize: 10.0,
                fontWeight: FontWeight.normal,
              ),
            ),
          ),
        ],
      ),
    );
  }
}

class InputSelect extends StatelessWidget {
  const InputSelect(
      {@required this.index,
      @required this.widget,
      @required this.parent,
      @required this.choice})
      : super();

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.all(8.0),
      child: ChoiceChip(
          label: Text(choice),
          //未选定的时候背景
          selectedColor: Color(0xff182740),
          //被禁用得时候背景
          disabledColor: Colors.grey[300],
          labelStyle: TextStyle(fontWeight: FontWeight.w200, fontSize: 15.0),
          labelPadding: EdgeInsets.only(left: 8.0, right: 8.0),
          materialTapTargetSize: MaterialTapTargetSize.padded,
          onSelected: (bool value) {
            parent.onSelectedChanged(index);
          },
          selected: parent.selected == index),
    );
  }

  final int index;
  final widget;
  final parent;
  final String choice;
}
